<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style>
        .demo{
            margin-bottom:10px;
        }
    </style>
</head>
<body>

 <div class="container">
     <div class="row">
         <nav class="navbar navbar-default navbar-static-top">
             <div class="container-fluid">
                 <div class="navbar-header">
                     <a class="navbar-brand" href="../index.html">首页</a>
                 </div>
                 <ul class="nav navbar-nav">
                    <li class="active"><a href="javascript:void(0)">Link</a></li>
                    <li><a href="javascript:void(0)">Link2</a></li>
                 </ul>
             </div>
         </nav>
     </div>
     <div class="row demo" ng-app="MyAPP">
         <h3>AngularJS 依赖注入$provide示例，参考文章: <a href="http://sentsin.com/web/663.html" target="_blank">http://sentsin.com/web/663.html</a> </h3>
         <div ng-controller="FirstController">
             <button ng-click="hello()">Click Me</button>
         </div>
         <br>
         <div ng-controller="SecondController">
             <button ng-click="hello()">Click Me</button>
         </div>
         <br>
         <div ng-controller="ThirdController">
             <button ng-click="hello()">Click Me</button>
         </div>
     </div>
 </div>
 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script>
    var app=angular.module("MyAPP",[]);

    app.provider('greeting1', function() {
        this.$get = function() {
            return function(name) {
                alert("Hello, " + name);
            };
        };
    });

    app.factory('greeting2', function() {
        return function(name) {
            alert("Hello, " + name);
        };
    });

    app.value('greeting3', function(name) {
        alert("Hello, " + name);
    });

    //在控制器中注入对象
    app.controller('FirstController', function($scope, greeting1) {
        $scope.hello = function() {
            greeting1("FirstController");
        }
    });
    app.controller('SecondController', function($scope, greeting2) {
        $scope.hello = function() {
            greeting2("SecondController");
        }
    });
    app.controller('ThirdController', function($scope, greeting3) {
        $scope.hello = function() {
            greeting3("ThirdController");
        }
    });
</script>
